using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace WindowsGame1.CoreComponents
{
    public class BackgroundComponent :
Microsoft.Xna.Framework.DrawableGameComponent
    {
        Texture2D background; //The image we want as the background
        SpriteBatch spriteBatch = null;
        Rectangle bgRect; //Location where the image will be drawn

        /// <summary>
        /// The rectangle to draw the background is made the size of the window
        /// </summary>
        /// <param name="game"></param>
        /// <param name="texture"></param>
        public BackgroundComponent(Game1 game, Texture2D texture, bool fill)
            : base(game)
        {
            this.background = texture;
            spriteBatch =(SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
            if (fill)
            {
                bgRect = new Rectangle(0, 0, Game.Window.ClientBounds.Width, Game.Window.ClientBounds.Height);
            }
            else
            {
                bgRect = new Rectangle((Game.Window.ClientBounds.Width - texture.Width) / 2,
                                        (Game.Window.ClientBounds.Height - texture.Height) / 2,
                                        texture.Width, texture.Height);
            }
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Draw(background, bgRect, Color.White);
            base.Draw(gameTime);
        }
    }
}